<template>
  <li @mouseenter="isShow = true" @mouseleave="isShow = false">
    <label>
      <input type="checkbox" v-model="isDone" />
      <span>{{ todo.name }}</span>
    </label>
    <button v-show="isShow" class="btn btn-danger" @click="del">删除</button>
  </li>
</template>

<script>
export default {
  name: "TodoItem",
  props: {
    todo: Object,
    updateTodoIsDone: Function,
    delTodo: Function,
  },
  data() {
    return {
      isShow: false,
    };
  },
  computed: {
    isDone: {
      get() {
        return this.todo.isDone;
      },
      set() {
        this.updateTodoIsDone(this.todo.id);
      },
    },
  },
  methods: {
    del() {
      if (window.confirm("您确认要删除当前代办事项吗")) {
        this.delTodo(this.todo.id);
      }
    },
  },
};
</script>

<style>
/*item*/
/* 样式 */
/* li:hover button.btn.btn-danger {
  display: block;
} */
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li label {
  /* float: left; */
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button.btn.btn-danger {
  float: right;
  /* display: none; */
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}
</style>